package com.neegix.log.loginLog.application.service.impl;

import com.neegix.application.command.BaseService;
import com.neegix.exception.BusinessRuntimeException;
import com.neegix.log.loginLog.application.cqrs.command.BatchDeleteLoginLogCommand;
import com.neegix.log.loginLog.application.cqrs.command.NewLoginLogCommand;
import com.neegix.log.loginLog.application.cqrs.command.UpdateLoginLogCommand;
import com.neegix.log.loginLog.application.cqrs.query.LoginLogQueryRepository;
import com.neegix.log.loginLog.application.service.LoginLogService;
import com.neegix.log.loginLog.domain.entity.LoginLogEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-12-19 15:39:21
  */

@Service
public class LoginLogServiceImpl extends BaseService implements LoginLogService{
    @Autowired
    private LoginLogQueryRepository loginLogQueryRepository;

    @Override
    public Void createLoginLog(LoginLogEntity loginLogEntity) {
        return commandInvoker.execute(new NewLoginLogCommand(loginLogEntity));
    }

    @Override
    public Void modifyLoginLog(LoginLogEntity loginLogEntity) {
        return commandInvoker.execute(new UpdateLoginLogCommand(loginLogEntity));
    }

    @Override
    public Void removeLoginLog(List<Long> ids) {
        Integer count = loginLogQueryRepository.selectCount(ids);
        if (count.equals(0)){
            throw new BusinessRuntimeException("要删除的记录不存在！");
        }
        return commandInvoker.execute(new BatchDeleteLoginLogCommand(ids));
    }
}
